{extend name="template/base_default"}
{block name="header"}
<link rel="stylesheet" href="__CSS__/common.css">
<link rel="stylesheet" href="__CSS__/weui.min.css">
<link rel="stylesheet" href="__CSS__/index.css">
<link rel="stylesheet" href="__CSS__/weuix.min.css"/>
<script src="__JS__/zepto.min.js"></script>
<script src="__JS__/lrz.min.js"></script>
<script type="text/javascript" src="__JS__/public.js"></script>
<style>
    .login-form{
        background: white;
    }
    body{
        background-image:url("__IMG__/bj.png");
        background-repeat:no-repeat;
        background-size:cover;
        text-align: center;
    }

    .logo{
        width: 100%;
        height: 100%;
        opacity: 0;
        -webkit-tap-highlight-color: rgba(0,0,0,0);
    }
    .input-window{
        width: 100%;
        height: 100%;
        opacity: 0;
        -webkit-tap-highlight-color: rgba(0,0,0,0);
    }
    .form-input2-input{
        line-height: 16px;
    }
</style>
{/block}
{block name="body"}
<div id="personalHeader" onclick="">
    <ul>
        <div class="c-logo" style="background-size: cover;background-image: url(__BASE__/index.php/picture/index?id={$memberinfo.head})">
            <input class="logo headimgurl" type="file" accept="image/jpg,image/jpeg,image/png,image/gif"   />
            <input  type="hidden"  id="head"  value="{$memberinfo.head}" />
        </div>
    </ul>
</div>
<form action="{:url('login/register')}" method="post" style="width:80%;margin: auto">

    <div class="form-input2" >
        <label for="nickname" class="form-input2-label">昵称</label>
        <input class="form-input2-input" id="nickname" name="nickname" type="text" value="{$memberinfo.nickname}" placeholder="昵称">
    </div>
    <div class="form-input2">
        <label for="sex" class="form-input2-label">性别</label>
            <input class="form-input2-input" name="sex" id="sex" type="text" data-values="{$memberinfo.sex}"
                   {eq name="memberinfo.sex" value="1"}
                   value="女"
                   {else/}
                    value="男"
                    {/eq} >

    </div>
    <div class="form-input2">
        <label for="sign" class="form-input2-label">简介</label>
        <input class="form-input2-input" id="sign" name="sign" type="text" value="{$memberinfo.sign}" placeholder="介绍下自己">
    </div>

    <div class="form-input">
        <button id="submit" class="login-btn" type="button">保存</button>
    </div>

</form>
{/block}
{block name="footer"}
<script type="text/javascript" src="__JS__/public.js"></script>
<script>
    $(function(){

        $('.headimgurl').change(function () {
            var v_this = $(this);
            lrz(this.files[0],{width:640,fieldName:"image"}).then(function (rst) {
                var formdata = new FormData();
                v_this.parent().css("background-image","url("+rst.base64+")");//无论是否上传成功都显示
                url = "__BASE__/web.php/file/upload_picture_base64";
                formdata.append("image", rst.base64);
                $.ajax({
                    url : url,
                    type : 'post',
                    data : formdata,
                    contentType : false,
                    processData : false,
                    dataType : "json",
                    success : function(data) {
                        if (data.status == true) {
                            $.toast("图片上传成功");
                            v_this.next().val(data.info[0]['id']);
                        }
                    },
                    error:function(){
                        $.toast("图片上传失败");
                    }
                });
                return false;
            })
        });
    });

    $("#sex").select({
        title: "性别",
        items: [
            {
                title: "男",
                value: "2",
            },
            {
                title: "女",
                value: "1"
            }
        ]
    });
    $('#submit').click(function () {

        var body  ={
            nickname:$('#nickname').val(),
            sign:$('#sign').val(),
            sex:$('#sex').data("values"),
            head:$('#head').val()
        };
        var $this = $(this);
        $this.addClass('weui-btn_disabled').attr('disabled','disabled');
        ajax_post(getBaseUrl()+'web.php/user/userinfo',jQuery.param(body),{
            success:function(data){
                $.toast("修改成功",'success');
                $this.removeClass('weui-btn_disabled').removeAttr("disabled");
//                setTimeout(
//                        function(){
//                            window.location.href=getBaseUrl()+'web.php/index/index.html';
//                        }
//                        ,1500);
            },
            error:function(data){
                $.toptip(data.data, 'error');
                $this.removeClass('weui-btn_disabled').removeAttr("disabled");
            }
        })


    });

</script>
{/block}